package file_;

import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileReader;

/**
 * 获得文件行数的方法
 * 有 bufferedReader.readLine 方法 或者查找byte是否=='\n',比较谁快！
 */
public class FileTest04 {
    public static void main(String[] args) {
        long start = System.nanoTime();
        try {
            BufferedReader reader = new BufferedReader(new FileReader("F:\\汤舒青.txt"));
        int i=0;
        while (reader.readLine()!=null){
            i++;
        }
        reader.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
        long end=System.nanoTime();
        System.out.println("时间"+(end-start));
        long start1=System.nanoTime();
        try {
            int i=0;
            FileInputStream stream = new FileInputStream("F:\\汤舒青.txt");
            byte[] b = new byte[stream.available()];
            int length=0;
            while ((length=stream.read(b))!=-1){
                i++;
                String s = new String(b, 0, length);
            }
            stream.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
        long end1=System.nanoTime();
        System.out.println("时间2为"+(end1-start1));


    }
}
